home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mc51bugs.zip / Q40113 < prev    next >
Text File  |  1989-01-06  |  2KB  |  58 lines

  1. Q40113 Incorrect Code Generation with /J
  2. C Compiler
  3. 5.00 5.10 | 5.10
  4. MS-DOS    | OS/2
  5.  
  6. Summary:
  7.  
  8. If the following program is compiled with the /J compiler option
  9. (which changes the default for char type from signed to unsigned) in
  10. the Microsoft C Optimizing Compiler Versions 5.00 and 5.10, it will
  11. not calculate the value of the long integer variable "result"
  12. correctly:
  13.  
  14. #include <stdio.h>
  15. void main(void)
  16. {
  17. unsigned long result = 'b';
  18.  
  19. result = result - 'a' + 1  ;
  20. printf("result = %lx", result) ;
  21. }
  22.  
  23. Compiled without /J, the program works correctly. Replacing "-a+1"
  24. with "-96", or using a char type variable to store the value "a" also
  25. prevents the problem.
  26.  
  27. Microsoft has confirmed this to be a problem in Versions 5.00 and
  28. 5.10. We are researching this problem and will post new information as
  29. it becomes available.
  30.  
  31.  
  32. More Information:
  33.  
  34. The following is the assembly-code listing generated with /J :
  35.  
  36. ;|*** unsigned long result = 'b';
  37.         mov     WORD PTR [bp-4],98      ;result
  38.         mov     WORD PTR [bp-2],0
  39. ;|***
  40. ;|*** result = result - 'a' + 1  ;
  41.         add     WORD PTR [bp-4],-96     ;This sets the carry flag
  42.                                         ;incorrectly.
  43.         adc     WORD PTR [bp-2],0
  44.  
  45.  
  46. The following is the code generated without /J :
  47.  
  48. ;|*** unsigned long result = 'b';
  49.         mov     WORD PTR [bp-4],98      ;result
  50.         mov     WORD PTR [bp-2],0
  51. ;|***
  52. ;|*** result = result - 'a' + 1  ;
  53.         sub     WORD PTR [bp-4],96      ;result
  54.         sbb     WORD PTR [bp-2],0
  55.  
  56. Keywords:  buglist5.00 buglist5.10
  57. Updated  89/01/06 07:29
  58.